<?php
require("../include/db.php");
require("../include/head.php");
?>
<?
$sqla="select * from company,mailing,member,membermailing";
$sqla.=" where company.id=mailing.companyid";
$sqla.=" and mailing.id=membermailing.mailingid";
$sqla.=" and member.id= membermailing.memberid";
$sqla.=" and company.id=".$_GET["compayid"];
$conn=getconnection();
$result = mysql_query($sqla, $conn);
$companycount = mysql_num_rows($result);
?>
<h1>Location:</h1>
<table border="0" id="contentTabled" width="200">
<?
$sqlb="select city,count(*) from company,mailing,member,membermailing";
$sqlb.=" where company.id=mailing.companyid";
$sqlb.=" and mailing.id=membermailing.mailingid";
$sqlb.=" and member.id= membermailing.memberid";
$sqlb.=" and company.id=".$_GET["compayid"];
$sqlb.=" group by member.city";
$result=mysql_query($sqlb,$conn);
while   ($row=mysql_fetch_array($result))
{
	echo "<tr>";
	echo "<td>".$row["city"]."</td>";
	echo "<td>".round(($row[1]*100)/$companycount,2)."%</td>";
	echo "</tr>";
}
?>
</table>
<h1>Sex:</h1>
<table border="0" id="contentTabled" width="200">
<?
$sqlc="select gender,count(*) from company,mailing,member,membermailing";
$sqlc.=" where company.id=mailing.companyid";
$sqlc.=" and mailing.id=membermailing.mailingid";
$sqlc.=" and member.id= membermailing.memberid";
$sqlc.=" and company.id=".$_GET["compayid"];
$sqlc.=" group by member.gender";
$resultc=mysql_query($sqlc,$conn);
while   ($rowc=mysql_fetch_array($resultc))
{
	echo "<tr>";
	echo "<td>".$rowc["gender"]."</td>";
	echo "<td>".round(($rowc[1]*100)/$companycount,2)."%</td>";
	echo "</tr>";
}
?>
</table>
<h1>Age:</h1>
<table border="0" id="contentTabled" width="200">
<?
$sqld="select birthday,count(*) from company,mailing,member,membermailing";
$sqld.=" where company.id=mailing.companyid";
$sqld.=" and mailing.id=membermailing.mailingid";
$sqld.=" and member.id= membermailing.memberid";
$sqld.=" and company.id=".$_GET["compayid"];
$sqld.=" group by member.birthday";
$resultd=mysql_query($sqld,$conn);
while   ($rowd=mysql_fetch_array($resultd))
{
	echo "<tr>";
	echo "<td>".$rowd["birthday"]."</td>";
	$tyear=split("-",date("Y-m-d h:i:s",time()));
	$ayear=split("-",$rowd["birthday"]);
	echo "<td>".($tyear[0]-$ayear[0])."</td>";
	echo "<td>".round(($rowd[1]*100)/$companycount,2)."%</td>";
	echo "</tr>";
}
?>
</table>
<?php
mysql_close($conn);
?>